package org.testing;

import java.io.Serializable;
import java.util.ArrayList;

public class CardStorage implements Serializable
{
	int randomCard;
	private ArrayList<Card> cardStore;
	
	  /**
     * Sole constructor.
     */
	public CardStorage()
	{
		cardStore=new ArrayList<Card>();
	}
	
	/**
	 * Returns a Random Int  
	 * 
	 * @return      a random number between 0-arraysize
	 * @see         ArrayList
	 */
	public int getRandomCardNum()
	{
		/*
		 * return random number between 0 and
		 * number of cards in the arrayList
		 */
		randomCard = (int) (Math.random()*cardStore.size());
		return randomCard;
	}
	
	/**
	 * Returns a Car object at specified location.
	 *
	 * @param  a  	the location of the Card object in the ArrayList
	 * @return      the Card object at the specified location
	 * @see         Card
	 */
	public Card getCard(int a)
	{
		return cardStore.get(a);
	}
	
	/**
	 * Returns the size of the ArrayList  
	 * 
	 * @return      the size of the ArrayList
	 * @see         ArrayList
	 */
	public int getArraySize()
	{
		return cardStore.size();
	}
	
	/**
	 * adds a Card object.  
	 *
	 * @param  a  	the Card object to be added into the ArrayList
	 * @see         Card ArrayList
	 */
	public void addItem(Card a)
	{
		cardStore.add(a);
	}
	
	/**
	 * finds out if a card exists with specified rating
	 * and difficulty  
	 *
	 * @param  minRating  	minimum rating
	 * @see    maxDiff		max difficulty
	 */
	public int getMinRatingMaxDiffCard(int minRating, int maxDiff)
	{
		for(int i=0; i<cardStore.size();i++)
		{
			if(cardStore.get(i).getOverallRating()>=minRating)
			{
				if(cardStore.get(i).getDifficultyRating()<=maxDiff)
				{
					return i;
				}
			}
		}
		return -1;
	}
	
	/**
	 * Clears everything from the ArrayList 
	 *
	 * @see         ArrayList
	 */
	public void clear()
	{
		cardStore.clear();
	}
}
